<?php

class Fpt_Business_TeamSeason_Adapter_Mysql extends Fpt_Business_TeamSeason_Adapter_Abstract
{

    /**
     *
     * @return Fpt_Business_TeamSeason_Adapter_Mysql 
     */
    public static function getInstance()
    {
        if (!isset(self::$instance) || !self::$instance instanceof self)
            self::$instance = new self;
        return self::$instance;
    }

    public function getListTableRanking($seasonId, $leagueId)
    {
        try
        {
            // Get DB instance
            $objDB = Fpt_Global::getSportSlaveDB();

            // Prepare SQL
            $stmt = $objDB->prepare('Call sp_code_sport_getBangXepHang(:p_league_id, :p_season_id);');

            // Bind params
            $stmt->bindParam('p_league_id', $leagueId, PDO::PARAM_INT);
            $stmt->bindParam('p_season_id', $seasonId, PDO::PARAM_INT);

            // Excute
            $stmt->execute();

            // Fetch to get result
            $result = array();
            $teamSeasonFormat = new Fpt_Business_TeamSeason_Metadata_TeamSeason();
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
            {
                $result[$row['team_id']] = $teamSeasonFormat->init($row)->getFormatedData();
            }

            // Release variables
            unset($stmt, $teamSeasonFormat);

            // Return result
            return $result;
        }
        catch (Exception $ex)
        {
            Fpt_Log::sendlog(4, $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), null, null);
            return false;
        }
    }
    /**
     * Get Team Detail
     * @param int $teameID
     * @return array
     * @author  : trint
     */
    public function getDetailTeam($teameID)
    {
        $arrResult = array();
        try
        {
            $sport_m = Fpt_Global::getSportDB();

            $stmt = $sport_m->prepare('CALL sp_besport_getDetailTeam(:p_teamid)');

            //Bind param
            $stmt->bindParam('p_teamid', $teameID, PDO::PARAM_INT);

            //Fetch result
            $stmt->execute();
            $arrResult = $stmt->fetch();
            //Close cursor
            $stmt->closeCursor();

            //Release
            unset($stmt);
        }
        catch (Zend_Exception $ex)
        {
            
            //log error
            Fpt_Log::sendlog(4, $ex->getCode(), $ex->getMessage(), $ex->getTraceAsString(), null, null);
            return false;
        }
        return $arrResult;
    }
}